local hx__tiandu = fk.CreateSkill {
  name = "hx__tiandu",
}

hx__tiandu:addEffect(fk.FinishJudge, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__tiandu.name) and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player, data.card, true, fk.ReasonJustMove)
  end,
})

hx__tiandu:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__tiandu.name) and player.phase == Player.Play
      and player:getMark("@hx__tiandu") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage{
      from = nil,
      to = player,
      damage = 1,
      skillName = hx__tiandu.name,
      isVirtualDMG = true,
    }
  end,
})

hx__tiandu:addEffect(fk.RoundEnd, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local roundCount = player.room:getBanner("RoundCount")
    return target == player and player:hasSkill(hx__tiandu.name) and (roundCount % 2 == 0 and roundCount > 1)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@hx__tiandu", 0)
  end,
})

hx__tiandu:addEffect(fk.AfterSkillEffect, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__tiandu.name) and data.skill.name == "hx__tiandu" and player:usedEffectTimes(self.name) < 20
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@hx__tiandu", 0)
  end,
})


hx__tiandu:addEffect(fk.RoundStart, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local roundCount = player.room:getBanner("RoundCount")
    return player:hasSkill(hx__tiandu.name) and (roundCount % 2 == 1 or roundCount == 1)
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@hx__tiandu", 1)
  end,
})

return hx__tiandu